python/xc: Fix multiple issues in pyflask_context_to_sid()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 9 Dec 2014 16:43:22 +0000 (16:43 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 16 Dec 2014 12:43:35 +0000 (12:43 +0000)
commit3f727fb1a7d5f3be2513ab2e692b067075325fb3
tree5401c30f5eefe17d8d7fbb920bd3a55fc3c37f90
parentdcd84861b0b01b8895716d4c803c9d24c31c8cab
python/xc: Fix multiple issues in pyflask_context_to_sid()

The error handling from a failed memory allocation should return
PyErr_SetFromErrno(xc_error_obj); rather than simply calling it and continuing
to the memcpy() below, with the dest pointer being NULL.

Coverity also complains about passing a non-NUL terminated string to
xc_flask_context_to_sid().  xc_flask_context_to_sid() doesn't actually take a
NUL terminated string, but it does take a char* which, in context, used to be
a string, which is why Coverity complains.

One solution would be to use strdup(ctx) which is simpler than a
strlen()/malloc()/memcpy() combo, which would result in a NUL-terminated
string being used with xc_flask_context_to_sid().

However, ctx is strictly an input to the hypercall and is not mutated along
the way.  Both these issues can be fixed, and the error logic simplified, by
not duplicating ctx in the first place.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Coverity-IDs: 1055305 1055721
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Xen Coverity Team <coverity@xen.org>
tools/python/xen/lowlevel/xc/xc.c